package org.example.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.model.entity.User;
import org.example.model.vo.R;
import org.example.service.UserService;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/auth")
@RequiredArgsConstructor
public class LoginController {

    private final UserService userService;

    @PostMapping("/login")
    public R<User> login(@RequestBody User user) {
        return R.ok(userService.login(user));
    }

    @GetMapping("/test")
    public R<Authentication> testLogin() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return R.ok(authentication);
    }
}